using BunnyEater.Common.ResponseOutput;
using BunnyEater.Domain.Base;
using BunnyEater.Service.SystemManagementService.RoleService;
using BunnyEater.Service.SystemManagementService.RoleService.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace BunnyEater.WebAPI.Controllers.SysManage
{
    /// <summary>
    /// 角色管理控制器，提供角色的增删改查及分页等接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(GroupName = "SYSTEM")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        private readonly IRoleService _roleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public RolesController(IRoleService roleService)
        {
            _roleService = roleService;
        }







        /// <summary>
        /// 分页查询角色列表
        /// </summary>
        [HttpGet]
        public async Task<ResponseReturnsEntity<Page<RoleListDto>>> GetPagedRoles([FromQuery] RolePagedQueryDto query)
        {
            return await _roleService.GetPagedRolesAsync(query);
        }

        /// <summary>
        /// 根据ID获取角色
        /// </summary>
        [HttpGet]
        public async Task<ResponseReturnsEntity<RoleListDto>> GetRoleById(string id)
        {
            return await _roleService.GetRoleById(id);
        }

        /// <summary>
        /// 新增角色
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> AddRole(RoleListDto roleDto)
        {
            return await _roleService.AddRole(roleDto);
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> UptRole(RoleListDto roleDto)
        {
            return await _roleService.UptRole(roleDto);
        }

        /// <summary>
        /// 删除角色（软删除）
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> DeleteRole(string id)
        {
            return await _roleService.DeleteRole(id);
        }

        /// <summary>
        /// 修改角色状态
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> UpdateRoleState(string id, bool state)
        {
            return await _roleService.UpdateRoleState(id, state);
        }

        /// <summary>
        /// 获取角色详情（包含权限ID和名称）
        /// </summary>
        /// <param name="id">角色Id</param>
        /// <returns>角色详情</returns>
        [HttpGet("detail/{id}")]
        public async Task<ResponseReturnsEntity<RoleDetailDto>> GetRoleDetailById(string id)
        {
            return await _roleService.GetRoleDetailById(id);
        }
    }
}